package swt.web;


import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import swt.dao.SaleDao;
import swt.entity.All;
import swt.servic.SaleServic;


public class SearchServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
		
		protected void service(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, IOException {
			String task=request.getParameter("task");
			if ("search".equals(task)) {
				search(request, response);
			}
		}

		private void search(HttpServletRequest request,HttpServletResponse response) 
				throws ServletException, IOException {
			
			String starttime = new String(request.getParameter("starttime").getBytes("ISO8859-1"),"UTF-8");
			String endtime = new String(request.getParameter("endtime").getBytes("ISO8859-1"),"UTF-8");
			
			String compname = new String(request.getParameter("compname").getBytes("ISO8859-1"),"UTF-8");
			String trname = new String(request.getParameter("trname").getBytes("ISO8859-1"),"UTF-8");
			String penum = new String(request.getParameter("penum").getBytes("ISO8859-1"),"UTF-8");
			String address= new String(request.getParameter("address").getBytes("ISO8859-1"),"UTF-8");
			String mintotal = new String(request.getParameter("mintotal").getBytes("ISO8859-1"),"UTF-8");
			String maxtotal = new String(request.getParameter("maxtotal").getBytes("ISO8859-1"),"UTF-8");
			SaleServic ser = new SaleServic();
			String where = ser.getWhere(starttime, endtime, compname, trname, penum, address,
					mintotal, maxtotal);
			System.out.println(where);
			
			SaleDao saledao=new SaleDao();
			HttpSession session=request.getSession();
			
			List<All> listSearch=saledao.findSearch(where);
			request.setAttribute("listAll", listSearch);
			request.getRequestDispatcher("WEB-INF/view/main.jsp").forward(request,
					response);
		}
}
